/*
https://leetcode-cn.com/problems/rotate-array/solution/xuan-zhuan-shu-zu-by-leetcode-solution-nipk/
 */
import java.util.Arrays;

public class Solution189 {
    public void rotate(int[] nums, int k) {
        k=k%nums.length;
        for (int l=0,r=nums.length-1;l<r;l++,r--){
            int temp=nums[l];
            nums[l]=nums[r];
            nums[r]=temp;
        }
        for (int l=0,r=k-1;l<r;l++,r--){
            int temp=nums[l];
            nums[l]=nums[r];
            nums[r]=temp;
        }
        for (int l=k,r=nums.length-1;l<r;l++,r--){
            int temp=nums[l];
            nums[l]=nums[r];
            nums[r]=temp;
        }
    }

    public static void main(String[] args) {
        int[] nums=new int[]{1,2,3,4,5,6,7};
        new Solution189().rotate(nums,3);
        System.out.println(Arrays.toString(nums));
    }
}
